//
//  Permissioner.swift
//  DaRings
//
//  Created by 尹琼 on 2022/12/8.
//

import UIKit
import CoreLocation

open class Permissioner: NSObject {

    /// 通知权限
    public static func userNotification() {
        
        guard #available(iOS 10, *) else {
            // 请求授权
            let typeValue = UIUserNotificationType.alert.rawValue |
            UIUserNotificationType.badge.rawValue |
            UIUserNotificationType.sound.rawValue
            let type = UIUserNotificationType(rawValue: typeValue)
            let setting = UIUserNotificationSettings(types: type, categories: nil)
            UIApplication.shared.registerUserNotificationSettings(setting)
            
            // 发送请求
            UIApplication.shared.registerForRemoteNotifications()
            return
        }
        let typeValue = UNAuthorizationOptions.alert.rawValue |
        UNAuthorizationOptions.badge.rawValue |
        UNAuthorizationOptions.sound.rawValue
        UNUserNotificationCenter.current().requestAuthorization(options: UNAuthorizationOptions(rawValue: typeValue)) { (granted, error) in
            if granted { // 同意
                UIApplication.shared.registerForRemoteNotifications()
            } else { // 拒绝
                /// 弹出提示框
            }
        }
        
    }
}

